<?php

namespace App\Kuafu\Banner\Validate;

use App\Kuafu\Banner\Model\BannerModel;
use Illuminate\Http\Request;
use App\Kuafu\Base\Validate\BaseValidate;

class BannerValidate extends BaseValidate
{

    /**
     * 广告列表添加/修改参数验证
     *
     * @param Request $request
     * @return string
     */
    public static function addOrSetBanner(Request $request)
    {
        $rules    = [
            'configId'  => 'required|integer|min:0',
            'imageUrl'  => 'required',
            'name'      => [
                'required',
                'max:10',
                function ($attribute, $value, $fail) use ($request) {
                    if (BannerModel::query()->where('name', $request['name'])->first()) {
                        $fail("广告名称重复");
                    }
                }
            ],
            'url'       => 'required',
            'startTime' => 'required',
            'endTime'   => 'required',
            'status'    => 'required|integer|between:0,1',
        ];
        $messages = [];
        return self::validateCheck($request->all(), $rules, $messages);
    }

    /**
     * 广告图片列表
     *
     * @param Request $request
     * @return string
     */
    public static function getBanner(Request $request)
    {
        $rules    = [
            'status' => 'required|integer|between:0,1',
        ];
        $messages = [];
        return self::validateCheck($request->all(), $rules, $messages);
    }

    /**
     * 删除
     *
     * @param $data
     * @return string
     *
     */
    public static function delAdList($data)
    {
        $rules    = [
            'id' => 'required|integer|min:0',
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

    /**
     * 横幅详情
     *
     * @param $data
     * @return string
     */
    public static function getBannerById($data)
    {
        $rules    = [
            'required｜integer｜min:0',
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

    /**
     * 小程序横幅列表
     * @param $data
     * @return string
     */
    public static function getBannerList($data)
    {
        $rules = [
            'required｜numeric｜min:0',
        ];

        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }


}
